/*
 * NAME, etc.
 *
 * sync.h
 */

#ifndef _STHREAD_SYNC_H_
#define _STHREAD_SYNC_H_

#include <stdlib.h>
#include <stdio.h>

typedef struct sthread_list {
	sthread_t* thread;
	struct sthread_list* next;
} sthread_list_t;

sthread_list_t* add_thread(sthread_list_t* p_head, sthread_t* p_sth);
sthread_list_t* pop_thread(sthread_list_t* p_head);
int destroy_sthread_list(sthread_list_t* p_head);

typedef struct sthread_sem_struct {
  int						count;
  int						n_waiting;
  volatile unsigned long    lock;
  struct sthread_list*		wait_queue;
} sthread_sem_t;

int sthread_list_init(sthread_list_t* p_sth_list, sthread_t* p_sth);
int sthread_sem_init(sthread_sem_t *sem, int count);
int sthread_sem_destroy(sthread_sem_t *sem);
int sthread_sem_down(sthread_sem_t *sem);
int sthread_sem_try_down(sthread_sem_t *sem);
int sthread_sem_up(sthread_sem_t *sem);

#endif
